<% layout('/layouts/default.html', {title: '渠道结算管理', libs: ['validate','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(chJiesuan.isNewRecord ? '新增渠道结算' : '编辑渠道结算')}
			</div>
			<div class="box-tools pull-right hide">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${chJiesuan}" action="${ctx}/ch/chJiesuan/update" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="id"/>
				<#form:hidden path="fapiaoUrl"/>
				<#form:hidden path="examineStatus" defaultValue="1"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('结算编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="jiesuanCode" disabled="true" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('结算金额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="jiesuanJine" maxlength="6" disabled="${chJiesuan.examineStatus!=null}" class="form-control number" onChange="jisuanJine()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('实际到账金额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="actualJine" disabled="true" maxlength="6" class="form-control number"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('结算类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="jiesuanType" items="${types}" disabled="true" itemLabel="desc" itemValue="code" class="form-control" onChange="jiesuanLeixing()"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row" id="duisi" style="display: none;">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('收款人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="alipayName" maxlength="255" disabled="true" class="form-control"/>
							</div>
						</div>
					</div>

					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('支付宝账户')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="alipayCode" maxlength="255" disabled="true" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row" id="duigong">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('税率')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="shuilv" items="${shuilvs}" disabled="true" itemLabel="desc" itemValue="code" maxlength="255" class="form-control" onChange="jiesuanLeixing()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('公司名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="companyName" maxlength="255" disabled="true" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('开户行')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="bankName" maxlength="255" disabled="true" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('银行账户')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="bankCode" maxlength="255" disabled="true" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row" id="duigongUpLoad">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('发票附件上传')}：</label>
							<div class="col-sm-10">
								<a class="btn btn-info btn-xs blue" target="_blank" href="${chJiesuan.fapiaoUrl}"><i class="fa fa-download"></i> 下载 </a>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('ch:chJiesuan:edit')){ %>
							<% if (chJiesuan.examineStatus=='1'){ %>
								<div class="btn btn-primary" onclick="updateJiesuanStatus(2)"><i class="fa fa-check" ></i> ${text('通 过')}</div>&nbsp;
<!--								<div class="btn" id="btnSubmitBohui"><i class="fa fa-close"></i> ${text('驳 回')}</div>&nbsp;-->
								<div class="btn btn-sm " style="background: #f1f1f1;border: 1px solid transparent;" onclick="updateJiesuanStatus(3)"><i class="fa fa-close"></i> ${text('驳 回')}</div>&nbsp;
							<% } %>
							<% if (chJiesuan.examineStatus=='2'){ %>
								<div class="btn btn-primary" onclick="updateJiesuanStatus(4)"><i class="fa fa-check" ></i> ${text('打 款')}</div>&nbsp;
							<% } %>
							<% if (chJiesuan.examineStatus=='3'){ %>
							<button  class="btn btn-sm" onclick="javascript:return false;"><i class="fa fa-close"></i> ${text('审核未通过')}</button>&nbsp;
							<% } %>

							<% if (chJiesuan.examineStatus=='4'){ %>
							<button  class="btn btn-sm" onclick="javascript:return false;"> ${text('已打款')}</button>&nbsp;
							<% } %>
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		return;

    }
});
</script>
<script>

	var jiesuanType = `${chJiesuan.jiesuanType}`;

	if(jiesuanType==1){
		$("#duisi").show();
		$("#duigong").hide();
		$("#duigongUpLoad").hide();
	}else{
		$("#duisi").hide();
		$("#duigong").show();
		$("#duigongUpLoad").show();
	}

	function updateJiesuanStatus(status){
		$.post("${ctx}/ch/chJiesuan/updateStatus",{id:`${chJiesuan.id}`,examineStatus:status},function (data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		})
		return false;
	}

	//切换结算类型
	function jiesuanLeixing(){
		var jiesuanType = $('#jiesuanType').val();
		console.log(jiesuanType);
		if(jiesuanType==1){
			$("#duisi").show();
			$("#duigong").hide();
			$("#duigongUpLoad").hide();
		}else{
			$("#duisi").hide();
			$("#duigong").show();
			$("#duigongUpLoad").show();
		}
		jisuanJine();
	}
	//计算实际到账金额
	function jisuanJine(){
		var jine = $("#jiesuanJine").val();
		if(jine == ''){
			$("#actualJine").val("");
			return;
		}
		var jiesuanType = $('#jiesuanType').val();
		if(jiesuanType==1){
			var actualJine = jine*(100-6)/100;
			$("#actualJine").val(actualJine);
			return;
		}
		if(jiesuanType==2){
			var shuilv = $('#shuilv').val();
			var actualJine = jine*(100-(6-shuilv))/100;
			$("#actualJine").val(actualJine);
			return;
		}

	}
</script>